<template>
  <div class="login-panel">
    <h1 class="title">后台管理系统</h1>
    <el-tabs type="border-card" stretch v-model="currentTab">
      <el-tab-pane name="account">
        <template #label>
          <span>
            <el-icon><avatar /></el-icon>账号登录
          </span>
        </template>
        <login-account ref="accountRef" />
      </el-tab-pane>
      <el-tab-pane name="phone">
        <template #label>
          <span>
            <el-icon><cellphone /></el-icon>手机登录
          </span>
        </template>
        <login-phone ref="phoneRef" />
      </el-tab-pane>
    </el-tabs>
    <div class="keep-password">
      <el-checkbox v-model="isRemember">记住密码</el-checkbox>
      <el-link type="primary">忘记密码</el-link>
    </div>
    <el-button class="login-btn" type="primary" @click="handleLoginClick"
      >立即登录</el-button
    >
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'
import LoginAccount from '@/views/login/conps/login-account.vue'
import LoginPhone from '@/views/login/conps/login-phone.vue'

export default defineComponent({
  name: 'login-panel',
  components: { LoginPhone, LoginAccount },
  setup() {
    //记住密码
    const isRemember = ref(false)
    const accountRef = ref<InstanceType<typeof LoginAccount>>()
    const phoneRef = ref<InstanceType<typeof LoginPhone>>()
    const currentTab = ref('account')
    //点击登录按钮
    const handleLoginClick = () => {
      if (currentTab.value === 'account') {
        //账号登录
        //调用login-account组件的loginAction这个方法
        accountRef.value?.loginAction(isRemember.value)
      } else {
        //手机号登录
      }
    }
    return {
      isRemember,
      accountRef,
      phoneRef,
      currentTab,
      handleLoginClick
    }
  }
})
</script>

<style lang="less">
.title {
  text-align: center;
}
.login-panel {
  width: 320px;
  margin-bottom: 120px;
}
.el-icon {
  margin-right: 2px;
}
.keep-password {
  display: flex;
  margin-top: 7px;
  justify-content: space-between;
}
.login-btn {
  padding: 0;
  width: 100%;
  margin: 5px 0 0;
}
</style>
